<template>
  <div class="login-box row">
    <div class="logo-box row-center">
      <img
        src="https://alpha-assets.obs.cn-east-3.myhuaweicloud.com/employ/20220420-101842.png"
        style="width: 180px;"
      >
    </div>
    <el-divider class="divider" direction="vertical" content-position="left" />
    <el-form
      ref="form"
      :model="form"
      inline
      size="normal"
      class="form mt30"
      label-position="left"
      label-width="80px"
    >
      <h3>逸格用工后台管理系统</h3>
      <el-form-item>
        <el-input v-model="form.userName" class="inputItem" prefix-icon="el-icon-user" placeholder="请输入用户名" />
      </el-form-item>
      <el-form-item>
        <el-input v-model="form.password" class="inputItem" prefix-icon="el-icon-key" type="password" placeholder="请输入密码" />
      </el-form-item>
      <el-form-item class="buttons">
        <el-button class="button" type="primary" @click="onSubmit">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { login } from '@/api/user'
import { mixpanelTracker } from '../../utils'
import { setToken } from '@/utils/auth'
import md5 from 'js-md5'
export default {
  data() {
    return {
      form: {
        userName: '',
        password: '',
        type: 1
      },
      loading: false
    }
  },
  methods: {
    async onSubmit() {
      this.loading = true
      try {
        const from = { ...this.form }
        from.password = md5(from.password)
        const res = await login(from)
        setToken(res.data.token)
        window.localStorage.setItem('userInfo', JSON.stringify(res.data))
        this.$router.push({ path: '/', query: this.otherQuery })
        this.loading = false
        mixpanelTracker('portal.login.success', {
          desc: '登录页-登录成功',
          data: this.loginForm
        })
      } catch (err) {
        this.loading = false
      }

      //   await login(this.form).then(res => {
      //     this.loading = true
      //     setToken(res.data.token)
      //     this.$store.dispatch('user/login', this.form).then(() => {
      //       this.$router.push({ path: '/', query: this.otherQuery })
      //       this.loading = false
      //       mixpanelTracker('portal.login.success', {
      //         desc: '登录页-登录成功',
      //         data: this.loginForm
      //       })
      //     })
      //       .catch(() => {
      //         this.loading = false
      //       })
      //   })
    }
  }
}
</script>
<style lang="scss" scoped>
body {
  background-color: #e78c4b;
}

.login-box {
  position: relative;
  box-sizing: border-box;
  width: 650px;
  height: 280px;
  left: 50%;
  top: 30%;
  transform: translateX(-50%);
  background-color: #ffffff;
  border-radius: 16px;
  box-shadow: rgba(136, 136, 136, 0.2) 10px 10px 20px;
  .logo-box {
    width: 300px;
    height: 350px;
  }
  h3 {
    width: 100%;
    font-size: 20px;
    padding-left: 5px;
    text-align: left;
    color: #666666;
  }
  .divider {
    position: relative;
    height: 180px;
    right: 15px;
  }
  .el-form-item {
    width: 200px;
  }
  i {
    display: inline-block;
    width: 20px;
    height: 20px;
    font-size: 16px;
  }

  .form {
    display: inline-block;
    width: 250px;
    height: 350px;
    margin: 0 auto;
    padding-top: 40px;
  }
  .buttons {
    display: flex;
    justify-content: center;
    margin-left: 25px;
  }
  .button {
    width: 250px;
    margin: 0px;
    border-radius: 6px;
    margin-top: 10px;
  }
  .inputItem {
    width: 250px !important;
  }
  .el-form-item {
    margin-bottom: 10px;
    margin-right: 0;
    .el-input {
      width: auto;
    }
    .el-input__inner {
      width: 300px;
    }
    .el-textarea__inner {
      width: 250px;
      margin-bottom: 0px;
    }
  }
}
</style>
